package com.wanbatv.wangwangba.Pager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wanbatv.wangwangba.R;
import com.wanbatv.wangwangba.chengzhang.ChengzhangDemo;


/**
 * Created by 俞亚楠 on 2015/8/26.
 */
public class page2 extends RelativeLayout{
    private Context context;
    private AttributeSet attrs;
    public static ImageView chengzhang_gengduo_iv;
    public static ImageView chengzhang_iv1;
    public static ImageView chengzhang_iv2;
    public static ImageView chengzhang_iv3;
    public static ImageView chengzhang_iv4;
    public static boolean IS_F2=false;
    public static TextView chengzhang_tv11;
    public static TextView chengzhang_tv12;
    public static TextView chengzhang_tv21;
    public static TextView chengzhang_tv22;
    public static TextView chengzhang_tv31;
    public static TextView chengzhang_tv32;
    public static TextView chengzhang_tv41;
    public static TextView chengzhang_tv42;




    public page2(Context context){
        super(context);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.page2_view, this, true);
    }

    public page2(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        this.attrs=attrs;
        LayoutInflater.from(context).inflate(R.layout.page2_view, this, true);
        chengzhang_gengduo_iv=(ImageView)findViewById(R.id.chengzhang_gengduo_iv);
        chengzhang_gengduo_iv.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    image_fangda(v,true);
                    IS_F2=true;
                    page1.IS_F1=false;
                    page3.IS_F3=false;
                    page4.IS_F4=false;
                    page5.IS_F5=false;
                }else{
                    image_fangda(v,false);
                }
            }
        });
        final ChengzhangDemo chengzhang_demo1=(ChengzhangDemo)findViewById(R.id.chengzhang_demo1);
        final ChengzhangDemo chengzhang_demo2=(ChengzhangDemo)findViewById(R.id.chengzhang_demo2);
        final ChengzhangDemo chengzhang_demo3=(ChengzhangDemo)findViewById(R.id.chengzhang_demo3);
        final ChengzhangDemo chengzhang_demo4=(ChengzhangDemo)findViewById(R.id.chengzhang_demo4);
        chengzhang_iv1=(ImageView)chengzhang_demo1.findViewById(R.id.chengzhang_demo_iv1);
        chengzhang_iv2=(ImageView)chengzhang_demo2.findViewById(R.id.chengzhang_demo_iv1);
        chengzhang_iv3=(ImageView)chengzhang_demo3.findViewById(R.id.chengzhang_demo_iv1);
        chengzhang_iv4=(ImageView)chengzhang_demo4.findViewById(R.id.chengzhang_demo_iv1);
        chengzhang_tv11=(TextView)chengzhang_demo1.findViewById(R.id.chengzhang_demo_tv1);
        chengzhang_tv12=(TextView)chengzhang_demo1.findViewById(R.id.chengzhang_demo_tv2);
        chengzhang_tv21=(TextView)chengzhang_demo2.findViewById(R.id.chengzhang_demo_tv1);
        chengzhang_tv22=(TextView)chengzhang_demo2.findViewById(R.id.chengzhang_demo_tv2);
        chengzhang_tv31=(TextView)chengzhang_demo3.findViewById(R.id.chengzhang_demo_tv1);
        chengzhang_tv32=(TextView)chengzhang_demo3.findViewById(R.id.chengzhang_demo_tv2);
        chengzhang_tv41=(TextView)chengzhang_demo4.findViewById(R.id.chengzhang_demo_tv1);
        chengzhang_tv42=(TextView)chengzhang_demo4.findViewById(R.id.chengzhang_demo_tv2);

        chengzhang_iv1.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    image_fangda(chengzhang_demo1,true);
                    IS_F2=true;
                    page1.IS_F1=false;
                    page3.IS_F3=false;
                    page4.IS_F4=false;
                    page5.IS_F5=false;
                }else{
                    image_fangda(chengzhang_demo1,false);
                }
            }
        });
        chengzhang_iv2.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    image_fangda(chengzhang_demo2,true);
                    IS_F2=true;
                    page1.IS_F1=false;
                    page3.IS_F3=false;
                    page4.IS_F4=false;
                    page5.IS_F5=false;
                }else{
                    image_fangda(chengzhang_demo2,false);
                }
            }
        });
        chengzhang_iv3.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    image_fangda(chengzhang_demo3,true);
                    IS_F2=false;
                    page1.IS_F1=false;
                    page3.IS_F3=false;
                    page4.IS_F4=false;
                    page5.IS_F5=false;
                }else{
                    image_fangda(chengzhang_demo3,false);
                }
            }
        });
        chengzhang_iv4.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    image_fangda(chengzhang_demo4,true);
                    IS_F2=false;
                    page1.IS_F1=false;
                    page3.IS_F3=false;
                    page4.IS_F4=false;
                    page5.IS_F5=false;
                }else{
                    image_fangda(chengzhang_demo4,false);
                }
            }
        });

    }
    public void image_fangda(View v, boolean hasFocus){
        if (hasFocus) {
            v.getParent().bringChildToFront(v);

            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale);
            ani.setFillAfter(true);
            v.startAnimation(ani);
        } else {
            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale_in);
            ani.setFillAfter(true);
            v.startAnimation(ani);
        }
    }
}
